﻿using Microsoft.Owin.Hosting;
using Sustainalytics.Websites.Admin.Library;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainalytics.Websites.Admin.WindowsService
{
    /// <summary>
    /// Console app startup.
    /// </summary>
    public static class ProgramConsole
    {

        public static void Start()
        {
            try
            {
                var url = string.Format("{0}", ConfigurationManager.AppSettings["hostUrl"]);
#if !DEBUG
                var uriBuilder = new UriBuilder(url);
                uriBuilder.Scheme = Uri.UriSchemeHttps;
                uriBuilder.Port = Int32.Parse(ConfigurationManager.AppSettings["httpsPort"]);
                url = uriBuilder.Uri.ToString();
#endif
                using (WebApp.Start<Startup>(url))
                {
                    System.Console.WriteLine("Started on: " + url);
                    System.Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
                System.Console.ReadKey();
            }
        }
    }
}
